package com.acanx.log4j2.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by ACANX on 2018/12/26.
 * IndexController : 首页基本控制器
 */

@RestController
public class IndexController {

    private static final Logger logger = LoggerFactory.getLogger(IndexController.class);
    /**
     * rootPage方法    默认首页
     * @return   String   homePageText
     */
    @RequestMapping(value = "/",produces = MediaType.TEXT_HTML_VALUE)
    //    @ResponseBody
    public String rootPage(){
        logger.debug("进入rootPage()方法");
        return "这是首页（新的首页）";
    }


    /**
     * indexPage方法注释   对应index页面
     * @return   String   indexPageText
     */
    @RequestMapping(value = "/index",produces = MediaType.TEXT_HTML_VALUE)
    // @ResponseBody
    public String indexPage(){
        logger.debug("进入indexPage方法");
        return "这是首页-index";
    }




    /**
     * helloPage 方法的注释  对应/index/hello
     * @return   String   helloPageText
     */
    @RequestMapping(value = "/index/hello",produces = MediaType.TEXT_HTML_VALUE)
    @ResponseBody
    public String helloPage(Model model, Map map, HttpServletRequest httpServletRequest){
        logger.debug("进入helloPage方法");
        model.addAttribute("atr1","atr1value");
        map.put("key","value");
        return "这是新首页-hello";
    }

    /**
     * helloWithNamePage 方法注释   对应/index页面
     * @return   String   indexPageText
     */
    @RequestMapping(value = "/hello/{name}/",produces = MediaType.TEXT_HTML_VALUE)
    // @ResponseBody
    public String helloWithNamePage(@PathVariable String name, Model model, Map map, HttpServletRequest httpServletRequest){
        logger.debug("进入helloWithNamePage方法");
        model.addAttribute("atr1","atr1value");
        map.put("key","value");
        /***
         * 方法中的注释文档
         */
        map.put("name",name);
        /* 多行注释   这是多行注释 */
        return "这是首页-新的hello "+name;// 行尾注释
    }
}
